/*
 * To change OSDetect template, choose Tools | Templates
 * and open the template in the editor.
 */

package netsend.server.common;

/**
 *
 * @author studio-x64
 */
import netsend.server.Main;
import org.apache.log4j.Category;

public class OSDetect extends Main{

    private static final Category log = Category.getInstance(Main.class.getName());
    private static String versionOS = "";
    private static String architectureOS = "";
    private static String nameOS = "";
    private static String jversion = "";
    private static String jhome = "";
    private static String jvmversion = "";
    private static String userhome = "";
    private static String sysusername = "";

    public static void getSysInfo()
    {        
        OSDetect.nameOS = System.getProperty("os.name");
        OSDetect.versionOS = System.getProperty("os.version");
        OSDetect.architectureOS = System.getProperty("os.arch");
        OSDetect.jversion = System.getProperty("java.version");
        OSDetect.jhome = System.getProperty("java.home");
        OSDetect.jvmversion = System.getProperty("java.vm.version");
        OSDetect.userhome = System.getProperty("user.home");
        OSDetect.sysusername = System.getProperty("user.name");
    }

    public static void logSysInfo()
    {
        getSysInfo();
        osArray();
        log.debug("Operating System: " + nameOS
                + "\nOperating System Version: " + versionOS
                + "\nOperating System Architecture: " + architectureOS
                + "\nJava Version: " + jversion
                + "\nJava Home: " + jhome
                + "\nJava Virtual Machine Version: " + jvmversion
                + "\nSystem Username: " + sysusername
                + "\nUser Home: " + userhome);
    }

    public static void osArray()
    {
        String[] osList = {"Windows 7","Linux","Mac OS","Mac OS X","Windows 95","Windows 98","Windows NT","Windows 2000","Windows XP","Windows 2003"};

        for(int i=0;i<10;i++)
        {
            if(nameOS.equals(osList[i]))
            {
                log.debug("Operating System supported.");
                i = 10;
            }
            else
            {
                log.debug("Operating System not supported.\nSystem closing...");
                i = 10;
                System.exit(-1);
            }
        }
    }

    public String getVersionOS() {
        return versionOS;
    }

    public void setVersionOS(String versionOS) {
        OSDetect.versionOS = versionOS;
    }

    public String getArchitectureOS() {
        return architectureOS;
    }

    public void setArchitectureOS(String architectureOS) {
        OSDetect.architectureOS = architectureOS;
    }

    public String getNameOS() {
        return nameOS;
    }

    public void setNameOS(String nameOS) {
        OSDetect.nameOS = nameOS;
    }

    public String getJversion() {
        return jversion;
    }

    public void setJversion(String jversion) {
        OSDetect.jversion = jversion;
    }

    public String getJhome() {
        return jhome;
    }

    public void setJhome(String jhome) {
        OSDetect.jhome = jhome;
    }

    public String getJvmversion() {
        return jvmversion;
    }

    public void setJvmversion(String jvmversion) {
        OSDetect.jvmversion = jvmversion;
    }

    public String getUserhome() {
        return userhome;
    }

    public void setUserhome(String userhome) {
        OSDetect.userhome = userhome;
    }

    public String getSysusername() {
        return sysusername;
    }

    public void setSysusername(String sysusername) {
        OSDetect.sysusername = sysusername;
    }
}
